#!/bin/bash
#
. ./public_functions.sh

get_cpu() {
  util=$(vmstat | awk 'NR==3 {print $13+$14}')
  iowait=$(vmstat | awk 'NR==3 {print $16}')
  logY "CPU-使用率：${util}%，等待磁盘IO响应使用率：${iowait}%"
}
get_cpu

get_memory() {
  total=$(free -m | awk 'NR==2 {printf "%.1f",$2/1024}')
  used=$(free -m | awk 'NR==2 {printf "%.1f",($2-$NF)/1024}')
  available=$(free -m | awk 'NR==2 {printf "%.1f",$NF/1024}')
  logY "内存-总大小：${total}G，已使用：${used}G，剩余：${available}G"
}
get_memory

get_disk() {
  fs=$(df -h | awk '/^\/dev/{print $1}')
  for i in $fs; do
    mounted=$(df -h | awk -v i=$i '$1==i {print $NF}')
    size=$(df -h | awk -v i=$i '$1==i {print $2}')
    used=$(df -h | awk -v i=$i '$1==i {print $3}')
    used_percent=$(df -h | awk -v i=$i '$1==i {print $5}')
    logY "硬盘-挂载点: $mounted, 总大小: $size, 已使用: $used, 使用率: $used_percent"
  done
}
get_disk

get_tcp_status() {
  summary=$(netstat -antp | awk '{a[$6]++} END{for(i in a) printf i":"a[i]" "}')
  logY "TCP连接状态: $summary"
}
get_tcp_status
